<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时</title>
    <style>
        .box {
            width: 580px;
            padding:10px;
            margin:100px auto;
            background-color: #369;
            border-radius: 5px;
            font-size: 30px;
            color: white;
            font-family:'Arial', "Microsoft YaHei UI";
        }
    </style>

    <script>
        window.onload = function () {
            var targetDate = new Date("2017/2/22");
            console.log(targetDate.toLocaleString());
            var box = document.getElementById("box");
            fn();
            setInterval(fn,1000);

            function fn() {
                var nowDate = new Date();
                var timer = targetDate.getTime() - nowDate.getTime();
                var second = parseInt(timer/1000);

                var d = zero(parseInt(second/(3600*24)));
                var h = zero(parseInt(second/3600%24));
                var m = zero(parseInt(second/60%60));
                var s = zero(parseInt(second%60));

                box.innerText = "距离老二生日还有:"+d+"天"+h+"小时"+m+"分钟"+s+"秒";
            }

            function zero(num) {
                return num<10&&num>=0 ? "0"+ num : num;
            }
        }
    </script>
</head>
<body>
    <div class="box" id="box"></div>
</body>
</html>